import json
from django.shortcuts import render,HttpResponse,get_object_or_404,HttpResponsePermanentRedirect
from django.template import loader
from django.urls import reverse
from django.views import generic
from django.http import JsonResponse
from django.views.decorators.csrf import csrf_exempt

from .models import *

# Create your views here.

@csrf_exempt
def get_b(request):
    if request.method == "POST":
        result = []
        for i in city.objects.filter(sheng_id=request.POST['id']):
            # 对应的id和ip组成一个字典
            result.append({'id': i.id,'name': i.name})
        return HttpResponse(json.dumps(result), content_type="application/json")
    # return JsonResponse(result)


@csrf_exempt
def get_c(request):
    if request.method == "POST":
        result = []
        for i in qu.objects.filter(city_id=request.POST['id']):
            # 对应的id和ip组成一个字典
            result.append({'id': i.id,'name': i.name})
        print('result',result)
        return HttpResponse(json.dumps(result), content_type="application/json")